window.onload = window.onresize = function() {
	var w = document.documentElement.clientWidth;
	if(w > 600) {
		document.body.style.width = '600px';
		document.body.style.margin = '0 auto';
		document.documentElement.style.fontSize = 20 * 600 / 750 + 'px';
		document.body.style.fontSize = 20 * 600 / 750 + 'px';
		console.log(document.body.style.fontSize);
	} else {
		document.body.style.width = w + 'px';
		document.body.style.margin = '0 auto';
		document.documentElement.style.fontSize = 20 * w / 750 + 'px';
		document.body.style.fontSize = 20 * 600 / 750 + 'px';
		console.log(document.body.style.fontSize);
	}
};
/**
 * 一些常用的js工具类
 * zhanglei 2017-03-07
 */

/**标准时间转换成可识别时间**/
function tf(i) {
	return(i < 10 ? '0' : '') + i
};
var format = function(time, format) {
	var t = new Date(time);
	var tf = function(i) {
		return(i < 10 ? '0' : '') + i
	};
	if(time == null) {
		return '';
	} else {
		return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a) {
			switch(a) {
				case 'yyyy':
					return tf(t.getFullYear());
					break;
				case 'MM':
					return tf(t.getMonth() + 1);
					break;
				case 'mm':
					return tf(t.getMinutes());
					break;
				case 'dd':
					return tf(t.getDate());
					break;
				case 'HH':
					return tf(t.getHours());
					break;
				case 'ss':
					return tf(t.getSeconds());
					break;
			}
		})
	}
}

var formatTimestamp = function formatTimestamp(timestamp, fmt) {
	var date = new Date(timestamp * 1000);
	var o = {
		"M+": date.getMonth() + 1, //月份 
		"d+": date.getDate(), //日 
		"H+": date.getHours(), //小时 
		"m+": date.getMinutes(), //分 
		"s+": date.getSeconds(), //秒 
		"q+": Math.floor((date.getMonth() + 3) / 3), //季度 
		"S": date.getMilliseconds() //毫秒 
	};
	if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}
//分页
function pageCtrl(option) {
	var total = option.total || 1;
	var current = parseInt(option.page) || 1;
	var max = Math.ceil(total / 10) || 1;

	function getNumbers() {
		if(max < 5) {
			var nums = [];
			for(var i = 0; i < max; i++) nums.push(i + 1);
			return nums;
		} else {
			return(current < 4) ? [1, 2, 3, 4, 5] : ((current > max - 3) ? [max - 4, max - 3, max - 2, max - 1, max] : [current - 2, current - 1, current, current + 1, current + 2]);
		}
	}

	function generatePager() {
		$('#numArea').html('');
		$('.front_page').attr('page-num', 1);
		$('.prev_page').attr('page-num', current - 1);
		$('.next_page').attr('page-num', current + 1);
		$('.end_page').attr('page-num', max).text(max);
		max > 5 && current > 4 && $('#numArea').append('<i>...</i>');
		var arr = getNumbers();
		for(var i = 0; i < arr.length; i++) {
			$('#numArea').append('<a' + (arr[i] == current ? ' class="current"' : ' href="#page-num"') + ' page-num="' + arr[i] + '">' + arr[i] + '</a>');
		}
		max > 5 && current < max - 3 && $('#numArea').append('<i>...</i>');
		current != 1 && $('.front_page').attr('href', '#page-num');
		max > 5 && current > 3 ? $('.front_page').show() : $('.front_page').hide();
		current > 1 ? $('.prev_page').attr('href', '#page-num').removeClass('current') : $('.prev_page').removeAttr('href').addClass('current');
		current < max ? $('.next_page').attr('href', '#page-num').removeClass('current') : $('.next_page').removeAttr('href').addClass('current');
		current != max && $('.end_page').attr('href', '#page-num');
		max > 5 && current < max - 2 ? $('.end_page').show() : $('.end_page').hide();
	}
	generatePager();
}

function pageCtrlFirstEnd(option) {
	var total = option.total || 1;
	var current = parseInt(option.page) || 1;
	var max = Math.ceil(total / option.pageSize) || 1;

	function generatePager() {
		$('.prev_page').attr('page-num', current - 1);
		$('.next_page').attr('page-num', current + 1);
		$('.end_page').attr('page-num', max);

		current > 1 ? $('.prev_page').attr('href', '#page-num').addClass('current') : $('.prev_page').removeAttr('href').removeClass('current');
		current < max ? $('.next_page').attr('href', '#page-num').addClass('current') : $('.next_page').removeAttr('href').removeClass('current');
		current != max ? $('.end_page').attr('href', '#page-num').addClass('current') : $('.end_page').removeAttr('href').removeClass('current');
	}
	generatePager();
}
/********获取url里参数**********/
var URL_ARGUMENTS = {};
if(location.search.length) {
	var args = location.search.slice(1).split('&');
	for(var i = 0; i < args.length; i++) {
		var arg = args[i].split('=');
		URL_ARGUMENTS[arg[0]] = arg[1];
	}
}

function GET() {
	if(arguments.length) {
		if(arguments[0] in URL_ARGUMENTS) {
			return URL_ARGUMENTS[arguments[0]];
		} else {
			//throw '"' + arguments[0] + '"参数不存在！';
			return false;
		}
	} else {
		return URL_ARGUMENTS;
	}
}

function sum(arr) {
	var result = 0;
	for(var i = 0; i < arr.length; i++) {
		result += parseInt(arr[i])
	}
	return result;
}
//获取移动设备类型(1&#45;&#45;Android;2&#45;&#45;IOS;0&#45;&#45;非移动设备;)
function getMobileType() {
	var ua = navigator.userAgent;
	if(!!ua.match(/AppleWebKit.*Mobile.*/)) {
		if(!!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
			return 2;
		}
		if(ua.indexOf('Android') > -1 || ua.indexOf('Linux') > -1) {
			return 1;
		}
	}
	return 0;
}